/**
 * keytool -import -alias cesium48 -keystore cesium-gateyway.jks -file MS_LSSGatewayClient_certMS_TLS_CLIENT.pem
 */

package org.jimmy.tang.ssl;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

/**
 * @author jimmy
 * 
 */
public class CiscoCesiumGatewayTest {

    public static void main(String[] args) throws IOException {
        HttpsURLConnection con = null;
        HostnameVerifier hv = new HostnameVerifier() {
            @Override
            public boolean verify(String urlHostName, SSLSession session) {
                return true;
            }
        };

        HttpsURLConnection.setDefaultHostnameVerifier(hv);
        setSystemKeyStoreProperty();
        setSystemTrustStoreProperty();
        URL url = new URL("https://10.140.29.48/cgi-bin/act2.ws");
        con = (HttpsURLConnection) url.openConnection();
        con.setRequestMethod("POST");

        con.setDoOutput(true);
        OutputStream os = con.getOutputStream();
        DataOutputStream wr = new DataOutputStream(os);
    }

    /**
     * 
     * @param keyStorePath
     * @param keyStorePassword
     * @param keyStoreType
     */
    public static void setSystemKeyStoreProperty() {
        System.setProperty("javax.net.ssl.keyStore",
                "/home/jimmy/temo/cert/keystore.jks");
        System.setProperty("javax.net.ssl.keyStorePassword", "cisco123");
        System.setProperty("javax.net.ssl.keyStoreType", "JKS");

    }

    /**
     * 
     * @param trustStorePath
     * @param trustStorePassword
     */
    public static void setSystemTrustStoreProperty() {
        System.setProperty("javax.net.ssl.trustStore",
                "/home/jimmy/temo/cert/truststore.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "cisco123");

    }

}
